<%--
  Created by IntelliJ IDEA.
  User: MadFrog
  Date: 2018/1/25
  Time: 23:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>签到</title>
<style type="text/css">
    html {height: 100%;}
    body{height: 100%; margin: 0px; padding: 0px;}
    #container{height: 100%; height: 85%; }
</style>
<script type="text/javascript" src="//api.map.baidu.com/api?ak=N4MKnjOjKqFc4TVVGKQ8qh36ODkmFLu9&type=lite&v=1.0"></script>
<script type="text/javascript" src="${ctx}/resources/wechat/jquery-weui-1.2.0/jquery-2.1.4.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="${ctx}/resources/wechat/js/wxConfig.js"></script>
<script type="text/javascript">
    wx.ready(function () {
        wx.getLocation({
            type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
            success: function (res) {
                // gps码转百度地图码，初始化地图
                $.ajax({
                    type: "get",
                    url : "http://api.map.baidu.com/geoconv/v1/?coords=" + res.longitude + "," + res.latitude + "&from=1&to=5&ak=N4MKnjOjKqFc4TVVGKQ8qh36ODkmFLu9",
                    dataType : 'JSONP',
                    success: function (res) {
                        if(res.status==0){
                            var map = new BMap.Map('container');
                            var point = new BMap.Point(res.result[0].x, res.result[0].y);
                            map.centerAndZoom(point, 15);
                            var marker = new BMap.Marker(point);
                            map.addOverlay(marker);
                        }
                    },
                    error: function (wechatReturn) {
                        alert("GPS坐标转换百度坐标失败!");
                    }
                });
                // 初始化地理位置信息
                $.ajax({
                    type: "get",
                    url : "http://api.map.baidu.com/geocoder/v2/?location=" + res.longitude + "," + res.latitude + "&output=json&ak=N4MKnjOjKqFc4TVVGKQ8qh36ODkmFLu9",
                    dataType : 'JSONP',
                    success: function (res) {
                        if(res.status==0){
                            $("#address").html("当前位置：" + res.result.formatted_address);
                        }
                    },
                    error: function () {
                        alert("获取百度地图标准化地址失败!");
                    }
                });
                // 注册“我要签到”按钮点击事件
                $("#btnSign").click(function(){
                    // console.log("/sms/admin/studentLecture/signIn/" + lId + "/" + res.latitude + "/" +　res.longitude);
                    $.ajax({
                        type: "get",
                        dataType : "html",
                        url: "/sms/admin/studentLecture/signIn",
                        data : {
                            lectureId : $("#lectureId").val(),
                            latitude : res.latitude,
                            longitude : res.longitude
                        },
                        success: function (res) {
                            $("#lectureSignInPage").html(res);
                        },
                        error: function () {
                            alert("签到失败，请联系管理员！");
                        }
                    });
                });
            },
            failure : function () {
                alert("微信JSSDK-getLocation()失败");
            }
        });
    });

</script>
</head>
<body>
    <div id="lectureSignInPage">
        <div id="container"></div>
        <dib id="address"></dib>
        <div class="next_btn" style="text-align: center; margin-bottom: 10px;">
            <input id="btnSign" type="button" value="我要签到" style="cursor: pointer; width: 210px; height: 50px; border-radius: 15px; background-color: #00CD00; border: 0px #FE6714 solid; cursor: pointer; color: white; font-size: 16px;" />
            <input type="hidden" id="lectureId" value="<%=session.getAttribute("lectureId")%>" />
        </div>
    </div>
</body>
</html>
